package cn.xiaoyu.su.manager.impl;

import cn.xiaoyu.su.enums.DomainTypeEnum;
import cn.xiaoyu.su.manager.DomainManager;
import cn.xiaoyu.su.mapper.DomainMapper;
import cn.xiaoyu.su.model.DomainDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class DomainManagerImpl implements DomainManager {

    @Autowired
    private DomainMapper domainMapper;

    /**
     * 查找详情
     * @param id
     * @param accountNo
     * @return
     */
    @Override
    public DomainDO findById(Long id, Long accountNo) {

        return domainMapper.selectOne(new QueryWrapper<DomainDO>().eq("id",id).eq("account_no",accountNo));

    }

    /**
     * 查找详情
     * @param id
     * @param domainTypeEnum
     * @return
     */
    @Override
    public DomainDO findByDomainTypeAndId(Long id, DomainTypeEnum domainTypeEnum) {
        return domainMapper.selectOne(new QueryWrapper<DomainDO>().eq("id",id).eq("domain_type",domainTypeEnum.name()));
    }

    /**
     * 新增
     * @param domainDO
     * @return
     */
    @Override
    public int addDomain(DomainDO domainDO) {
        return domainMapper.insert(domainDO);
    }

    /**
     * 列举全部官方域名
     * @return
     */
    @Override
    public List<DomainDO> listOfficialDomain() {
        return domainMapper.selectList(new QueryWrapper<DomainDO>().eq("domain_type",DomainTypeEnum.OFFICIAL.name()));
    }

    /**
     * 列举全部自定义域名
     * @param accountNo
     * @return
     */
    @Override
    public List<DomainDO> listCustomDomain(Long accountNo) {
        return domainMapper.selectList(new QueryWrapper<DomainDO>().eq("account_no",accountNo).eq("domain_type",DomainTypeEnum.CUSTOM.name()));
    }
}
